package com.anti.modular.bus.roomexpenses.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.anti.jdbc.DBUtils;
import com.anti.modular.bus.roomexpenses.entity.LeaseExpenses;
import com.anti.modular.bus.roomexpenses.entity.RoomExpenses;
import com.anti.modular.bus.roomexpenses.result.LeaseExpensesResult;
import com.anti.modular.bus.roomexpenses.result.RoomExpensesResult;
import com.anti.modular.bus.roomexpenses.service.LeaseExpensesService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;


/**
 * 房间费用表service接口实现类
 *
 * @author anti
 * @date 2021-04-18 17:08:44
 */
@Service
public class LeaseExpensesServiceImpl implements LeaseExpensesService {
    @Resource
    DBUtils dbUtils;

    @Override
    public void addEntity( LeaseExpenses leaseExpenses) {
        String s = dbUtils.insertKey(leaseExpenses).toString();
        leaseExpenses.setId(Long.parseLong(s));
    }

    @Override
    public List<LeaseExpensesResult> getByIds(List<Long> ids) {
        String sql="select a.*,b.id as house_bill_detail_id  from bus_lease_expenses A,house_bill_detail B where A.id =B.rent_amount_category and a.status =0 and b.id in (:ids)";
        HashMap<Object, Object> param = CollectionUtil.newHashMap();
        param.put("ids",ids);
        List<LeaseExpensesResult> roomExpenses = dbUtils.query(sql, LeaseExpensesResult.class, param);
        return roomExpenses;
    }

    @Override
    public List<LeaseExpenses> getLeaseExpensesLeaseId(Long leaseId) {
        String sql="select a.* from bus_lease_expenses a where  a.status =0 and a.lease_id =? ";
        List<LeaseExpenses> roomExpenses = dbUtils.query(sql, LeaseExpenses.class, leaseId);
        return roomExpenses;
    }

    /**
     *
     * @param leaseId
     * @param type 1 租金账单费用  0 水电账单费用
     * @return
     */
    @Override
    public List<LeaseExpenses> getLeaseExpensesLeaseIdAndType(Long leaseId, int type) {
        String sql="select a.* from bus_lease_expenses a where  a.status =0 and a.lease_id =? and ydzd=?";
        List<LeaseExpenses> roomExpenses = dbUtils.query(sql, LeaseExpenses.class, leaseId,type);
        return roomExpenses;
    }
}
